/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actions;

import com.paris5.master2.guitarmaster.bean.EcomCartRow;
import com.paris5.master2.guitarmaster.exception.EcomException;
import com.paris5.master2.guitarmaster.exception.EcomValidationException;
import com.paris5.master2.guitarmaster.service.ServiceCartRemoteE;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;

/**
 *
 * @author Leticia
 */
public class AjouterPanier extends EcomAction implements ServletRequestAware {
    private int idProduct;
    private int quantity;
    private HttpServletRequest request;

    @Override
    public String execute() throws IOException {
        try {
            ServiceCartRemoteE serviceCartRemoteE = (ServiceCartRemoteE) getFromSession("PANIER");
            if (serviceCartRemoteE == null) {
                serviceCartRemoteE = lookupServiceCartERemote();
                saveSession("PANIER", serviceCartRemoteE);
            }
            serviceCartRemoteE.add(idProduct, quantity);
            removeSession("TOTAL_PRICE");
            saveSession("TOTAL_PRICE", serviceCartRemoteE.getTotalPrice());
            return SUCCESS;
        } catch (EcomValidationException ex) {
            Logger.getLogger(AjouterPanier.class.getName()).log(Level.SEVERE, null, ex);
        } catch (EcomException ex) {
            Logger.getLogger(AjouterPanier.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ERROR;
    }

    @Override
    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }

    public int getIdProduct() {
        return idProduct;
    }

    public void setIdProduct(int idProduct) {
        this.idProduct = idProduct;
    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }
    
        public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }
}
